<?php

/**
 * 预购商品
 * ============================================================================
 * * 版权所有 20013-* 梅州络客网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.alork.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: index.php 17217 2013-10-19 06:29:08Z liubo $
*/


define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');


set_category_layer();

function set_category_layer(){
    
    $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '0' WHERE `parent_id` = 0");
    
    echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '0' WHERE `parent_id` = 0";
    echo '<br />';
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 0";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 1";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 2";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 3";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    
        
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 4";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    
        
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 5";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
    
    echo '<br />';
    
    $sql = "SELECT * FROM `egg_category` WHERE `layer` = 6";
    $res = $GLOBALS['db']->query($sql);
    
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $GLOBALS['db']->query("UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}");
        echo "UPDATE {$GLOBALS['ecs']->table('category')} SET `layer` = '" .($row['layer']+1) ."' WHERE `parent_id` = {$row['cat_id']}<br />";
    }
    
}

?>
